package com.yygo.jobs;

import com.yygo.model.LoanPerson;
import com.yygo.model.LoanRequest;
import com.yygo.model.Rule;
import com.yygo.service.LoanRequestManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * Created by tiansha on 2015/7/4.
 */
@Component("D501")
public class D501 implements RuleProcessor {

    @Autowired
    private LoanRequestManager loanRequestManager;

    @Override
    public Rule process(LoanRequest loanRequest) {
        LoanPerson requestPerson = loanRequest.getRequestPerson();
        float annualIncome = requestPerson.getAnnualIncome();
        float monthLoan = loanRequest.getMonthPaymentAmount();
        BigDecimal income = new BigDecimal(annualIncome);
        BigDecimal month = new BigDecimal(monthLoan);
        try {
            BigDecimal result = month.multiply(new BigDecimal(12)).divide(income);
            if (result.floatValue() > 0.5) {
                Rule rule = new Rule("D501", "月还款金额占家庭收入比重过大");
                return rule;
            }
        } catch (Exception ex) {
            Rule rule = new Rule("D501", "总收入为0");
            return rule;
        }

        return null;
    }

}